package com.mindata.blockchain.core.service.sqliteChecker;

import com.mindata.blockchain.core.manager.MessageManager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;

@RestController
@RequestMapping("/checker")
public class MessageCheck extends BaseCheckService implements checkService {

    @Resource
    private MessageManager messageManager;

    @GetMapping("/message")
    public HashMap<String,String> check(){
        return check("message",getJsonStringAndId());
    }

    @Override
    public HashMap<String, String> getJsonStringAndId() {
        HashMap<String,String> map = new HashMap<>();
        String messageId,content,json;
        for(int i=0; i<messageManager.findAll().size(); i++){
            messageId = messageManager.findAll().get(i).getMessageId();
            content = messageManager.findAll().get(i).getContent();
            json = "{\"content\":\"" + content + "\"}";
            map.put(messageId,json);
        }
        return map;
    }
}
